import java.util.ArrayList;
import java.util.List;

public class Main {

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public List<Integer> postorderTraversal(TreeNode root) {
            List<Integer> result = new ArrayList<>();
            postorder(root, result);
            return result;
        }

        // 递归辅助函数
        private void postorder(TreeNode node, List<Integer> result) {
            // 基准条件：如果节点为空，则返回
            if (node == null) {
                return;
            }

            // 遍历左子树
            postorder(node.left, result);
            // 遍历右子树
            postorder(node.right, result);
            // 访问当前节点
            result.add(node.val);
        }
    }


    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}